// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
//ElementUI
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);
//全局使用axios
import axios from "axios";
Vue.prototype.$axios = axios;
//允许携带cookie
axios.defaults.withCredentials = true;
axios.defaults.baseURL = 'http://127.0.0.1:8000/';
Vue.config.productionTip = false
//全局路由守卫
router.beforeEach(async (to, from,next) => {
  var isAuthenticated=false;
  axios.get('/user/finUser').then((response) => {
    if(res.code==1){
      isAuthenticated=true;
    }
    if (to.name !== 'login' && !isAuthenticated) next({ name: 'login' })
    else next()
  })
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
